import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author leijian
 * @version 1.0
 * @date 2019/6/4 17:19
 **/
public class Main {
    public static void main(String[] args) throws ParseException {
        System.out.println(hexStr2Str("0x02"));
        final byte[] b1 = {0x02};
        System.out.println(new String (b1));

    }


    public static String hexStr2Str(String hexStr) {
        String str = "0123456789ABCDEF";
        char[] hexs = hexStr.toCharArray();
        byte[] bytes = new byte[hexStr.length() / 2];
        int n;
        for (int i = 0; i < bytes.length; i++) {
            n = str.indexOf(hexs[2 * i]) * 16;
            n += str.indexOf(hexs[2 * i + 1]);
            bytes[i] = (byte) (n & 0xff);
        }
        return new String(bytes);

    }


    public static String toStringHex(String s) {
        byte[] baKeyword = new byte[s.length() / 2];
        for (int i = 0; i < baKeyword.length; i++) {
            try {
                baKeyword[i] = (byte) (0xff & Integer.parseInt(s.substring(
                        i * 2, i * 2 + 2), 16));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        try {
            s = new String(baKeyword, "utf-8");// UTF-16le:Not
        } catch (Exception e1) {
            e1.printStackTrace();
        }
        return s;
    }


    void Demo01() throws ParseException {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        calendar.set(2016, 00, 01);
        System.out.println(dateFormat.format(calendar.getTime()));
        System.out.println(calendar.getTimeInMillis());
        System.out.println(dateFormat.parse(dateFormat.format(calendar.getTime())).getTime());

        String beginDate = "1420041600000";
        beginDate = "1546272000000";

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        String sd = sdf.format(new Date(Long.parseLong(beginDate))); // 时间戳转换日期

        System.out.println(sd);
    }
}
